#!/bin/sh

source config

rm -f index_rich.md

for files in `ls -l $tag*.md |sed -e "/^l/d"|grep $tag|awk '{print $NF}'`
do

	grep "^#" $files |sed -e "/^#####/d" |awk -v ll=$files '{print $0 " " ll }' >>index_rich.md

done

sed -e "s/# /# [/" index_rich.md >tmp.md

sed -e "s/ $tag/\]\($tag/" tmp.md >index_rich.md

sed -e "s/_202.*/.html\)/" index_rich.md >tmp.md

#commcode bookheader > index_rich.md

echo "" > index_rich.md

awk '{print $0 "\n"}' tmp.md >>index_rich.md

